package com.masterclient.app.businessmodule.minemodule.store.contract;

import com.eoner.baselib.enums.FCPageViewState;
import com.eoner.baselib.presenter.FCBaseCallBack;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.businessmodule.minemodule.store.bean.CollectShopBean;
import com.masterclient.app.modules.search.SearchShopMessage;

import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;

/**
* Created by TMVPHelper on 2017/07/24
*/
public class ShopListPresenter extends ShopListContract.Presenter{

    public List<SearchShopMessage> lists = new ArrayList<>();

    @Override
    public void getCollectShopList(String page, String page_size,boolean isRefresh) {

        if (lists.size() == 0 && !isRefresh) {
            mView.baseShowPageLoading(false);
        }
        Observable<CommonBaseResponse<CollectShopBean>> observable = RetrofitUtil.getInstance().getCollectShopList(page,page_size);
        Disposable disposable = toNewSubscribe(observable, new FCBaseCallBack<CommonBaseResponse<CollectShopBean>>() {
            @Override
            public void onSuccess(CommonBaseResponse<CollectShopBean> bean) {
                mView.showShopList(bean.getData());
            }

            @Override
            public void onServiceError(CommonBaseResponse<CollectShopBean> bean) {
                super.onServiceError(bean);
                mView.baseShowError();
                if (lists.size() == 0) {
                    mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR);
                }
            }

            @Override
            public void onNetWorkError(String errorMsg) {
                super.onNetWorkError(errorMsg);
                mView.baseShowError();
                if (lists.size() == 0) {
                    mView.baseRefreshPageState(FCPageViewState.PAGE_STATE_NET_ERROR);
                }
            }
        });
        mRxManager.add(disposable);
    }
}